<template>
    <div class="jianzhuForm">
        <div class="radioList" style="margin: 0">
            <div class="top10">
                <label class="leftTitle">可透支金额：</label>
                <span class="name">
                    <el-input type="number" v-model="overSum" placeholder="-1为无限制透支"></el-input>
                </span>
                <label class="leftTitle">公共帐号：</label>
                <span class="name">
                    <!-- IS_PUBLIC是否公共账户(0否1是) -->
                    <el-radio v-model="isPublic" label="1">是</el-radio>
                    <el-radio v-model="isPublic" label="0">否</el-radio>
                </span>
            </div>
            <div class="top10">
                <label class="leftTitle">调整原因：</label>
                <el-input type="textarea" placeholder="调整原因描述" v-model="desc" style="width: 600px; margin: 0; padding: 0"></el-input>
            </div>

            <div class="top10">
                <el-checkbox v-model="isfhz" style="margin-left: 20px; color: red">立即进行分合闸操作</el-checkbox>
                <label class="leftTitle" style="color: red">密码验证：</label>
                <el-input type="password" v-model="pwd" placeholder="请输入密码" style="width: 200px"></el-input>
            </div>
        </div>
        <div class="radioList" style="margin-bottom: 10px; font-weight: bold; font-size: 14px">调整账户：</div>
        <el-table
            ref="multipleTable"
            :data="userInfoList"
            border
            tooltip-effect="dark"
            style="width: 100%"
            height="150"
            highlight-current-row
            @current-change="handleCurrentChange"
        >
            <el-table-column prop="AC_NAME" label="账户名称"> </el-table-column>
            <!-- IS_PUBLIC是否公共账户(0否1是)、 -->
            <el-table-column prop="IS_PUBLIC" label="公共账户" width="100">
                <template slot-scope="scope">
                    {{ scope.row.IS_PUBLIC == '1' ? '是' : '否' }}
                </template>
            </el-table-column>
            <el-table-column prop="AC_SUM" label="账户余额" width="180"> </el-table-column>
            <!-- （如为-1无限透支 、0未启用，其它展示金额） -->
            <el-table-column prop="OVER_SUM" label="透支金额" width="120">
                <template slot-scope="scope">
                    {{ scope.row.OVER_SUM == '-1' ? '无限制透支' : scope.row.OVER_SUM == '0' ? '不允许透支' : scope.row.OVER_SUM }}
                </template>
            </el-table-column>
        </el-table>

        <div style="text-align: right; margin-top: 10px">
            <el-button type="primary" @click="save">保存</el-button>
            <el-button @click="cancel">取消</el-button>
        </div>
    </div>
</template>

<script>
import {AjaxCommon} from '@/libs/apiCommon'
import {PopupCommon} from '@/libs/popupCommon'
export default {
    components: {},
    props: ['userInfo'],
    watch: {
        userInfo: {
            handler(user) {
                this.userInfoList = user ?? []
                this.ac_guids = (user ?? [])?.map((t) => t.AC_GUID)?.toString()
                // IS_PUBLIC
                this.isPublic = (user ?? [])?.filter((t) => t.IS_PUBLIC == 1)?.length == this.userInfoList.length ? '1' : '0'
            },
            immediate: true
        }
    },
    data() {
        return {
            ac_guids: '',
            userInfoList: [],
            pwd: '',
            overSum: '',
            isPublic: 1,
            currentRow: {},
            isfhz: true,
            desc: '',
            time: ''
        }
    },
    computed: {},
    created() {},
    mounted() {
        this.$nextTick(() => {})
    },
    methods: {
        async save() {
            if (this.overSum == '') {
                PopupCommon.notify('info', '请填写可透支金额')
                return
            }
            if (this.pwd == '') {
                PopupCommon.notify('info', '请填写验证密码')
                return
            }
            const res = await AjaxCommon('/api/OpenAccount/ChangeAccount', 'post', {
                ac_guids: this.ac_guids,
                isPublic: parseInt(this.isPublic),
                isfhz: this.isfhz ? 1 : 0,
                overSum: parseInt(this.overSum),
                desc: this.desc,
                pwd: this.pwd
            })
            if (res?.data?.Code == 200) {
                PopupCommon.notify('sucess', '透支额度调整成功')
                that.$emit('sucess', '')
            } else {
                let data = res?.data?.Message ?? '透支额度调整失败'
                PopupCommon.notify('fail', data)
            }
        },
        handleCurrentChange(val) {
            console.log(val, 'val....')
            this.currentRow = val
        },
        cancel() {
            this.$emit('close', '')
        }
    }
}
</script>

<style lang="scss" scoped>
.jianzhuForm {
    position: relative;
    top: -15px;
    .radioList {
        margin-top: 10px;
        padding-top: 10px;
        .name {
            font-weight: bold;
            font-size: 14px;
        }
        .top10 {
            margin-top: 10px;
            display: flex;
            line-height: 32px;
            .leftTitle {
                text-align: right;
                width: 90px;
                float: left;
            }
        }
    }
    .title {
        text-align: center;
        font-size: 18px;
        color: #000;
        padding-bottom: 10px;
        border-bottom: 1px solid #e0e0e0;
        margin-bottom: 10px;
    }
}
</style>
